    var form = layui.form, table = layui.table, $ = layui.jquery,id = getQueryVariable("id");

//表单初始值，修改时调用
    if (id != "") {
        form.val("editor-form", {
            "receiptno": "入库单号",
        })
    }
    $('#editor-form').find('input,textarea,select').attr('disabled',true);

    let detailData = [];
    let annexList = [];
    let operationLog = [];
    layer.ready(function () {
        //获取详情信息
        $.ajax({
            type:"POST",
            dataType:"json",
            contentType: 'application/json',
            data:JSON.stringify(id),
            url:"initStock/detail",
            async:false,
            success:function(res){
                if(res.status == 200){
                    //主表信息赋值
                    $("#billNo").val(res.data.billNo);
                    $("#createDate").val(res.data.createDate);
                    $("#operator").val(res.data.operator);
                    $("#inStorePerson").val(res.data.inStorePerson);
                    $("#warehouseName").val(res.data.warehouseName);
                    $("#memo").val(res.data.memo);

                    //产品列表信息
                    detailData = res.data.detailList;

                    if (!isEmpty(res.data.annexVos) && res.data.annexVos.length > 0) {
                        //附件信息
                        annexList = res.data.annexVos;
                    }

                    table.reload('storageproductstableid',{data : detailData});
                    table.reload('attachmenttableid',{data : annexList});

                    return false;
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
            }
        });
    })
//--入库产品信息
    table.render({
        elem: '#storageproducts',
        id: 'storageproductstableid',
        data: detailData,
        toolbar: '#storageproductstoolbar',
        cols: [[
            {field: 'img', title: '产品图片', width: 120, align: 'center', templet: '#imgTpl',event: 'productimg'},
            {field: 'warehouseName', width: 120, title: '仓库名称'},
            {field: 'lotNo', width: 100, title: '批次号'},
            {field: 'productCode', width: 120, title: '产品编码'},
            {field: 'specificationCode', width: 120, title: '规格编码', sort: true},
            {field: 'specificationExplanation', width: 120, title: '规格说明'},
            {field: 'productNum', width: 80, title: '数量'},
            {field: 'productUnit', width: 120, title: '单位'},
            {field: 'instoreUnitPrice', width: 80, title: '单价'},
            {field: 'moneySubtotal', width: 120, title: '金额小计'},
            {field: 'productUnitPrice', width: 120, title: '成本单价'},
            {field: 'shareCostPrice', width: 80, title: '分摊费用单价'},
            {field: 'costAmount', width: 120, title: '成本小计'},
            {field: 'trayNumber', width: 120, title: '托盘入数'},
            {field: 'totalTray', width: 120, title: '总托盘'},
            {field: 'supplierName', width: 120, title: '供应商名称'},
            {field: 'color', width: 120, title: '颜色'},
            {field: 'productCname', width: 120, title: '中文名称'},
            {field: 'productEname', width: 120, title: '英文名称'},
            {field: 'productCdesc', width: 120, title: '中文描述'},
            {field: 'productEdesc', width: 120, title: '英文描述'},
            {field: 'memo', width: 210, title: '备注'}
            ]],
        page: true,
        height: 380
        , done: function (res, curr, count) {
            hoverOpenImg();//显示大图
        }
    });

    function hoverOpenImg() {
        var img_show = null; // tips提示
        $("body").delegate("td img", "mouseover", function () {
            var img = "<img class='img_msg' src='" + $(this).attr('src') + "' style='width:130px;' />";
            img_show = layer.tips(img, this, {
                tips: [2, 'rgba(41,41,41,.5)']
                , area: ['160px']
            });
        });
        $("body").delegate("td img", "mouseout", function () {
            layer.close(img_show);
        });
    }


    //---附件
    table.render({
        elem: '#attachment'
        , data: annexList
        , toolbar: '#attachmenttoolbar'
        , cols: [[
            {field: 'fileName', title: '文件名', fixed: true}
            , {field: 'uploadTime', title: '上传日期', fixed: true}
            , {fixed: 'right', width: 180, align: 'center', toolbar: '#attachmenteditor', title: '操作'}
        ]]
        , id: 'attachmenttableid'
        , height: 380
        , page: true
    });

    table.on('tool(attachmenttable)', function (obj) {
        let data = obj.data;
        if (obj.event === 'download') { //下载
            let xmlHttpRequest = new XMLHttpRequest();
            let url = "wjinfo/downloadfile2?filename=" + data.filePath;
            xmlHttpRequest.open('GET', url, true);
            //设置请求头
            xmlHttpRequest.setRequestHeader("Content-type", "application/json")
            xmlHttpRequest.responseType = "blob";
            xmlHttpRequest.send(null);

            xmlHttpRequest.onload = function() {
                let content = xmlHttpRequest.response;
                // 组装a标签
                let elink = document.createElement("a");

                //设置文件下载路径
                elink.download = decodeURIComponent(data.fileName);
                elink.style.display = "none";
                let blob = new Blob([content], { type: 'application/force-download' });

                //解决下载不存在文件的问题，根据blob大小判断
                if(blob.size==0){
                    layer.msg('服务器没找到此文件，请联系管理员!');
                }else{
                    elink.href = window.URL.createObjectURL(blob);
                    document.body.appendChild(elink);
                    elink.click();
                    document.body.removeChild(elink);
                }

            }
        }
    });

//---操作日志
    table.render({
        elem: '#otherwarehouselog'
        , data: operationLog
        , cols: [[
            {field: 'operationtype', title: '操作类型', fixed: true}
            , {field: 'theoperator', title: '操作员'}
            , {field: 'operationdate', title: '操作日期'}
            , {field: 'modifythecontent', title: '修改内容'}
        ]]
        , id: 'logtableid'
        , height: 380
        , limit: 30//显示的数量
        , page: true
    });


    //字段是否为空或者零
    function isEmpty(obj){
        if(typeof obj == "undefined" || obj == null || obj == "" || obj == 0){
            return true;
        }else{
            return false;
        }
    }